﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LibraryMusicStore
{
    public class Stock
    {
        public static int GetStock(int id, IQueryable<Receipt> receipts, IQueryable<Issue> issues)
        {
            try
            {
                int nhap = 0, xuat = 0;
                
                foreach (var receipt in receipts)
                {
                    nhap += (from rd in receipt.ReceiptDetails
                             where rd.AlbumId == id
                             select rd.Quantity).Sum();
                }

                foreach (var issue in issues)
                {
                    xuat += (from iD in issue.IssueDetails
                             where iD.AlbumId == id
                             select iD.Quantity).Sum();
                }

                return nhap - xuat;
            }
            catch (Exception)
            {
                return 0;
            }
        }
    }
}
